package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.ConfirmationOfOrderPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.ConfirmationOfOrderView
import com.weetop.cfw.bean.AudioVideoDetailBean
import com.weetop.cfw.bean.OrderInfoBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.ConfirmationOfOrderActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class ConfirmationOfOrderPresenterImp(var confirmationOfOrderView:ConfirmationOfOrderView? = null):ConfirmationOfOrderPresenter {
    /**
     * 获取订单支付信息
     */
    override fun getOrderInfo(confirmationOfOrderActivity: ConfirmationOfOrderActivity, orderId: String) {
        confirmationOfOrderActivity.showLoadingDialog(confirmationOfOrderActivity,"正在获取订单信息...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getOrderInfo(orderId = orderId),confirmationOfOrderActivity,object:RxJavaCallBack<OrderInfoBean>(){

            override fun onSuccess(t: OrderInfoBean?) {
                if(t != null){
                    confirmationOfOrderActivity.dismissLoadingDialog()
                    confirmationOfOrderView?.showNativeShortToast("订单信息获取成功")
                    confirmationOfOrderView?.orderInfoGetSuccess(t)
                }
            }

            override fun onRequestError(t: OrderInfoBean?) {
                super.onRequestError(t)
                confirmationOfOrderView?.showNativeShortToast("订单信息获取失败")
                confirmationOfOrderActivity.dismissLoadingDialog()
            }

        })
    }

    /**
     * 获取课程详情
     */
    override fun getCourseDetail(confirmationOfOrderActivity: ConfirmationOfOrderActivity, inforId:Int) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getCloudCurriculumDetail(inforId),confirmationOfOrderActivity,object:RxJavaCallBack<AudioVideoDetailBean>(){

            override fun onSuccess(t: AudioVideoDetailBean?) {
                if(t != null){
                    confirmationOfOrderView?.courseDetailGetSuccess(t)
                }
            }

        })
    }


    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        confirmationOfOrderView = baseView as? ConfirmationOfOrderView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       confirmationOfOrderView = null
    }
}